package com.xy.dp.observer;

import java.util.ArrayList;
import java.util.List;

public class Teacher implements Subject {
    private String phone;
    private List observers;

    public Teacher() {
        observers = new ArrayList();
    }
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
        notifyObserver();
    }

    public List getObservers() {
        return observers;
    }

    public void setObservers(List observers) {
        observers = observers;
    }

    @Override
    public void registerObserver(Object o) {
        observers.add(o);
    }

    @Override
    public void removeObserver(Object o) {
        observers.remove(o);
    }

    @Override
    public void notifyObserver() {
        for (int i = 0; i < observers.size(); i++) {
            ((Observer)observers.get(i)).update(phone);
        }
    }
}
